package com.sms.platform.feign;

import com.sms.platform.common.constants.CacheConstants;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @author xjh
 * @date 2020-08-11
 */
@FeignClient("sms-platform-cache")
@RequestMapping("/cache")
public interface CacheService {
    @PostMapping(value = "/set")
    void save2Cache(@RequestParam("key") String key,
                           @RequestParam("value") String value,
                           @RequestParam("expireSecond") Integer expireSecond);

    /**
     * 把key和value放入redis的String中
     * 放入的value是String类型
     */
    @PostMapping("/set/{key}/{value}")
    boolean setString(@PathVariable String  key, @PathVariable String value);


    /**
     * 从redis的string中读取出指定的key的值
     * 取出的value是String类型
     */
    @GetMapping("/get/{key}")
    String getString(@PathVariable String key);

    /**
     * 接收前端传递过来的keys数组,然后从redis中删除keys数组中对应的key
     * 前端传递时,使用form表单格式 键值对 键:keys 值:FIRST_BLACK:13439988877, FIRST_BLACK:13437789988 多个值之间逗号间隔
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    boolean deleteKey(@RequestParam(value = "keys") String[] keys);

    /**
     * 从redis的hash中读取出指定key的数据
     */
    @GetMapping("/hmget/{key}")
    Map<Object, Object> hmget(@PathVariable String key);

    /**
     * 将map格式的数据放入redis的hash中
     */
    @PostMapping("/hmset/{key}")
    boolean hmset(@PathVariable String key, @RequestBody Map map);

    @RequestMapping("/hmget/"+ CacheConstants.CACHE_PREFIX_CLIENT +"{clientID}")
    String getClientInfo(@PathVariable String clientID);
}